var succ_btn = document.getElementById("success-btn");
function form_submit(params){
    var submit_flag = false;
    console.log('$("form").serialize(),:',$('form').serialize());
    $.ajax({
        url: "https://qmx.yangdiy.cn/form/addform",
        type: 'POST',
        data: $('form').serialize(),
        /*success: function (result,textStatus,xhr){
            insert(result,'work-select');
            console.log(arguments);
            console.log(xhr.status);  //状态码
            console.log(textStatus);
        },*/
        success: function (data){
            var _data = data.code;
            console.log('提交的_data=',_data);
            if(_data == 20000){
                submit_flag = true;
                name_check_flag = false;
                number_check_flag = false;
                alert("提交成功！");
                succ_btn.style.display="block";  //提交成功以后的提示
                succ_btn.className = "animated fadeIn" //赋予一定的动画
                location.reload();
                window.location.href = "https://yangaoyu.gitee.io/one_money/html/CTGU/success.html";
            }
        },
        error: function (data) {
            var _data = data.status;
            console.log(_data);
            if (_data == 401) {
                // console.log("请勿在一小时内多次提交");
                succ_btn.style.display="none";  //提交成功但重复提交 => 提交失败
                succ_btn.className = "" //清除样式
                console.log("存在多次提交或重名现象");
                alert("存在多次提交或重名现象");
                //clear_all();
                location.reload();
            }
        }
    })
}

function setCollege(){  //从数据库获取学院信息  =>  交给前台渲染
    $.ajax({
        url: "https://qmx.yangdiy.cn/college/searchc",
        type: 'get',
        success: function (data){
            console.log(data);   //data是获取到的json文件
            var colleges = data.data;  //data.data拿到json中名字为data的元素
            var html = '';
            for ( var i = 0; i < colleges.length; i++) {//循环json对象，拼接tr,td的html
                if(i == 0){
                    $("#work-select").val(colleges[i].college);
                }
                html+= '<option value="'+colleges[i].college +'">' +  colleges[i].college +'</option>';
            }
            $('#work-select').html(html);//通过jquery方式获取table，并把tr,td的html输出到table中
        },
        error: function (xhr,textStatus){
            console.log(xhr.status);
        }
    })
}

function setField(){   //从数据库获取场次信息 =>  给前台渲染
    $.ajax({
        url: "https://qmx.yangdiy.cn/field/searchf",
        type: 'GET',
        success: function (data){
            console.log(data);
            var fields = data.data;
            var html = '';
            for(var i = 0;i <fields.length;i++){
                html+= '<option value="'+fields[i].field +'">' +  fields[i].field +'</option>';
            }
            $('#session-select').html(html);//通过jquery方式获取table，并把tr,td的html输出到table中
        }
    })

}
